package lee.vioson.ebook.data

import android.content.Context
import androidx.annotation.StringRes
import lee.vioson.remotedata.repositories.HomeRepository
import lee.vioson.remotedata.repositories.HomeRepositoryImpl
import lee.vioson.remotedata.repositories.CacheFileRepository
import lee.vioson.remotedata.repositories.CacheFileRepositoryImpl
import lee.vioson.remotedata.repositories.InitRepository
import lee.vioson.remotedata.repositories.InitRepositoryImpl
import lee.vioson.remotedata.ApiServices
import lee.vioson.remotedata.RetrofitManager
import lee.vioson.remotedata.database.AppDataBase
import lee.vioson.remotedata.database.db
import lee.vioson.remotedata.repositories.BookRepository
import lee.vioson.remotedata.repositories.BookRepositoryImpl
import lee.vioson.remotedata.repositories.FeedbackRepository
import lee.vioson.remotedata.repositories.FeedbackRepositoryImpl
import lee.vioson.remotedata.repositories.LoginRepository
import lee.vioson.remotedata.repositories.LoginRepositoryImpl
import lee.vioson.remotedata.repositories.RegisterRepository
import lee.vioson.remotedata.repositories.RegisterRepositoryImpl
import lee.vioson.security.android_id

/**
 *Author:viosonlee
 *Date:2023/6/1
 *DESCRIPTION:
 */

interface AppContainer {
    var appEvent:AppEvent
    val api: ApiServices
    val initRepository: InitRepository
    val homeRepository: HomeRepository
    val cacheFileRepository: CacheFileRepository
    val registerRepository: RegisterRepository
    val loginRepository: LoginRepository
    val bookRepository: BookRepository
    val feedbackRepository:FeedbackRepository
    val uniqueId: String
    val customerSource: String
    val context: Context
    val db: AppDataBase
    fun stringResource(@StringRes resId: Int): String
}

//604d3675a37893d2
class AppContainerImpl(private val applicationContext: Context) : AppContainer {

    override lateinit var appEvent: AppEvent

    override val api: ApiServices by lazy {
        RetrofitManager().getApi(ApiServices::class.java)
    }

    override val initRepository: InitRepository by lazy {
        InitRepositoryImpl(context, api)
    }
    override val homeRepository: HomeRepository by lazy {
        HomeRepositoryImpl(context, api, db)
    }

    override val cacheFileRepository: CacheFileRepository by lazy {
        CacheFileRepositoryImpl(api)
    }
    override val registerRepository: RegisterRepository by lazy {
        RegisterRepositoryImpl(context, api)
    }
    override val loginRepository: LoginRepository by lazy {
        LoginRepositoryImpl(context, api)
    }
    override val bookRepository: BookRepository by lazy {
        BookRepositoryImpl(api)
    }
    override val feedbackRepository: FeedbackRepository by lazy {
        FeedbackRepositoryImpl(api)
    }

    override val db: AppDataBase by lazy {
        context.db
    }
    override val uniqueId: String
        get() = applicationContext.android_id
    override val customerSource: String
        get() = "test source"
    override val context: Context
        get() = applicationContext

    override fun stringResource(resId: Int) = applicationContext.getString(resId)

}